package com.bridgeintelligent.tag.engine.es.index;

import com.bridgeintelligent.tag.engine.api.DimInfo;
import com.bridgeintelligent.tag.engine.api.EngineConfig;
import com.bridgeintelligent.tag.engine.core.cache.CacheConfig;
import com.bridgeintelligent.tag.engine.core.cache.CacheUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by JackCheung on 2019/9/16 7:49 PM.
 */
public class EngineMappingHelper {

    public static final String TYPE = "onedata_cust_view";
//    public static final String TYPE = "onedata_flag_label_msys";

    /**
     * 创建索引字段映射
     *
     * @return Map
     */
    public static Map<String, Object> updateMapping() {
        Map<String, DimInfo> cacheMap = CacheUtils.getCacheMap(CacheConfig.DIM_INFO);
        Map<String, Object> fieldMap = new HashMap<>(cacheMap.size());
        cacheMap.forEach((k, v) -> {
            Map<String, String> typeMap = new HashMap<>(16);
            if (EngineConfig.QUANTITATIVE_DIM.equals(v.getDimType())) {
                typeMap.put("type", "double");
            } else {
                typeMap.put("type", "keyword");
            }
            fieldMap.put(k, typeMap);
        });
        Map<String, String> typeMap = new HashMap<>(16);
        typeMap.put("type", "keyword");
        fieldMap.put("cust_id", typeMap);
        Map<String, Object> propertiesMap = new HashMap<>(16);
        propertiesMap.put("properties", fieldMap);
        Map<String, Object> doc = new HashMap<>(propertiesMap.size());
        doc.put(TYPE, propertiesMap);
        return propertiesMap;
    }
}
